﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Threading;
using CoverageTestTechnology.Executor.CommandExecutor;
using CoverageTestTechnology.Report;

namespace AliyunMobileTestTechnology.ViewModel.Commands
{
    public class CompareDiffCommand:ICommand
    {
        private CoverageDiffViewModel coverageDiffVM;

        public CompareDiffCommand(CoverageDiffViewModel coverageDiffVM) 
        {
            this.coverageDiffVM = coverageDiffVM;
        }

        public bool CanExecute(object parameter)
        {
            return !coverageDiffVM.IsCommandExecuting;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            Thread t = new Thread(new ThreadStart(Compare));
            t.IsBackground = true;
            t.Start();
        }

        private void Compare() 
        {
            coverageDiffVM.IsCommandExecuting = true;
            try
            {
                //测试效果用
                System.Threading.Thread.Sleep(6000);

                //测试用路径
                string outPath=@"d:\test.cttd";

                DiffItem diffItem = CTTExecutor.Compare(coverageDiffVM.CttmPath, coverageDiffVM.CttrPath, outPath);
                coverageDiffVM.AffectedCases = diffItem.GetCoveredCasesSummaryForReducedBlocks();               
            }
            catch { }
            finally
            {
                coverageDiffVM.IsCommandExecuting = false;
            }           
        }
    }
}
